package com.example.joke

import android.content.Intent
import android.view.View
import android.view.View.OnClickListener
import android.widget.EditText
import android.widget.Toast
import com.example.joke.frame.BaseSkinActivity
import com.example.joke.databinding.ActivityMainBinding
import com.example.joke.base.dialog.AlertDialog
import com.example.joke.base.http.HttpCallBack
import com.example.joke.base.http.HttpUtils
import com.example.joke.base.navigationbar.AbsNavigationBar
import com.example.joke.custom.CustomActivity
import com.example.joke.frame.DefaultNavigationBar
import com.example.joke.proxy.ProxyActivity
import com.example.joke.select.UploadImageActivity
import com.example.joke.service.ServiceActivity

class MainActivity : BaseSkinActivity<ActivityMainBinding>() {
    override fun setListener() {
        binding.apply {
            tvService.setOnClickListener {
                startActivity(Intent(this@MainActivity, ServiceActivity::class.java))
            }
            tvUpload.setOnClickListener {
                startActivity(Intent(this@MainActivity, UploadImageActivity::class.java))
            }
            tvProxy.setOnClickListener {
                startActivity(Intent(this@MainActivity, ProxyActivity::class.java))
            }
            tvCustom.setOnClickListener {
                startActivity(Intent(this@MainActivity, CustomActivity::class.java))
            }
        }
    }


    override fun initData() {
//            val navigationBar = DefaultNavigationBar.Builder(this, findViewById(R.id.root))
        val navigationBar = DefaultNavigationBar.Builder(this)
            .setTitle("第二页")
//                .setLeftClickListener(object : OnClickListener {
//                    override fun onClick(v: View?) {
//                        finish()
//                    }
//                })
            .setRightText("右边")
            .setRightClickListener {
                Toast.makeText(
                    this@MainActivity,
                    "右边点击逻辑",
                    Toast.LENGTH_LONG
                ).show();
            }
            .builder<AbsNavigationBar.Builder.AbsNavigationParams>()


        HttpUtils.with(this).url("http://is.snssdk.com/2/essay/discovery/v3/")
            .addParam("iid","6152551759")
            .addParam("aid","7")
//            .execute(object : EngineCallBack {
            .execute(object : HttpCallBack<String>() {
//            override fun onPreExecute(context: Context, params: Map<String, Any>) {
//                // 每个接口都做共用参数添加/拼接，也很麻烦，所以再自己写一个回调的抽象类，
//                // 继承自EnginCallBack，去实现onPreExecute方法
//            }

                override fun onPreExecute() {
                    // 加载进度条

                }
                override fun onError(e: Exception) {
                    // 隐藏进度条

                }

                override fun onSuccess(result: String) {
                    // 隐藏进度条

                }

        })

    }

    override fun initTitle() {
        binding.tv.text = "哎嘿嘿。。。"
        binding.tv.setOnClickListener {
            val dialog: AlertDialog = AlertDialog.Builder(this)
                .setContentView(R.layout.dialog_demo)
                .setText(R.id.tv, "Dialog...")
                .setOnClickListener(R.id.tv, object : OnClickListener {
                    override fun onClick(v: View?) {
                        Toast.makeText(this@MainActivity, "我点击了", Toast.LENGTH_LONG).show();
                    }

                })
                .show()
            // 改成dialog去操作点击事件，特有操作对象，通过getView方法，比如需要知道LV,RV,cb等控件
            val et: EditText = dialog.getView(R.id.et);
            dialog.setOnClickListener(R.id.iv, object : OnClickListener {
                override fun onClick(v: View?) {
                    Toast.makeText(this@MainActivity, et.text.toString(), Toast.LENGTH_LONG).show();
                }
            })

            // TODO: 软键盘自动弹出
        }
    }

    override fun getBinding1(): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }
}